package com.iterator.controller.web.promotionController;


import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.bean.web.pojo.zql.InfoData;
import com.iterator.bean.web.pojo.zql.Coupon;
import com.iterator.bean.web.pojo.zql.CouponUser;
import com.iterator.bean.web.zql.bo.CouponBO;
import com.iterator.bean.web.zql.bo.CouponUserBO;
import com.iterator.service.web.promotionService.CouponService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author : L
 * @ProjectName : project-2
 * @Date : 1/9/2021
 * @Description :
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponController {
    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    @RequiresPermissions("admin:coupon:list")
    public BaseRespVo list(CouponBO couponBO) {
        InfoData<Coupon> couponInfoData = couponService.queryCouponList(couponBO);
        return BaseRespVo.ok(couponInfoData);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:coupon:create")
    public BaseRespVo create(@RequestBody Coupon coupon) {
        Coupon coupon1 = couponService.insertCoupon(coupon);
        return BaseRespVo.ok(coupon1);
    }

    @RequestMapping("update")
    @RequiresPermissions("admin:coupon:update")
    public BaseRespVo update(@RequestBody Coupon coupon) {
        couponService.updateCoupon(coupon);
        Coupon coupon1 = couponService.queryCoupon(coupon.getId());
        return BaseRespVo.ok(coupon1);
    }

    @RequestMapping("read")
    @RequiresPermissions("admin:coupon:read")
    public BaseRespVo read(Integer id) {
        Coupon coupon = couponService.queryCoupon(id);
        return BaseRespVo.ok(coupon);
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:coupon:delete")
    public BaseRespVo delete(@RequestBody Coupon coupon) {
        couponService.deleteCoupon(coupon.getId());
        return BaseRespVo.ok();
    }

    @RequestMapping("listuser")
    @RequiresPermissions("admin:coupon:listuser")
    public BaseRespVo listuser(CouponUserBO couponUserBO) {
        InfoData<CouponUser> couponUserInfoData = couponService.queryCouponUserList(couponUserBO);
        return BaseRespVo.ok(couponUserInfoData);
    }
}
